#ifndef __SPROTO_BIND_H__
#define __SPROTO_BIND_H__

extern "C" {
	struct sproto;
	struct sproto_type;
};

#include "core\reference.h"
#include "core\variant.h"


class Sproto : public Object {
	GDCLASS(Sproto, Object)

public:
	enum DispatchMode {
		NONE,
		REQUEST,
		RESPONSE
	};

private:
	struct sproto * m_sproto;
	PoolByteArray m_packBuffer;
	PoolByteArray m_unpackBuffer;
	PoolByteArray m_encodeBuffer;
	PoolByteArray m_decodeBuffer;
	String m_hostName;
	int m_session;
	Dictionary m_requests;
	Dictionary m_dispatch_requests;
	Dictionary m_header;
	
	struct sproto_type * get_sproto_type(const String& name);

protected:
	static void _bind_methods();

public:
	Sproto();
	~Sproto();
	void clearcache();
	bool newsproto(const PoolByteArray& buffer);
	bool deletesproto();
	void dumpsproto();
	PoolByteArray encode(const String& name, const Dictionary& data);
	Dictionary decode(const String& name, const PoolByteArray& buffer);
	PoolByteArray pack(const PoolByteArray& buffer);
	PoolByteArray unpack(const PoolByteArray& buffer);
	Dictionary protocol(const Variant& name);
	bool host(const String& name = String("package"));
	Dictionary dispatch(const PoolByteArray& buffer);
	PoolByteArray request(const String &name, const Variant &data = Variant(), const Variant &ud = Variant());
	PoolByteArray response(const String &name = String(""), const Variant &data = Variant(), const Variant &ud = Variant(), int session = 0);

};
VARIANT_ENUM_CAST(Sproto::DispatchMode);

#endif
